import Mock from "mockjs";
import { defineMock } from "vite-plugin-mock-dev-server";
import { resultSuccess, pageResultSuccess } from "./utils";

export default defineMock([
	{
		url: "/mock/randomUserList",
		method: ["GET"],
		body: () => {
			const mockData = Mock.mock({
				"list|5": [
					{
						id: "@id",
						name: "@cname",
						age: "@integer(1, 100)",
						address: "@county",
						city: "@city",
						province: "@province",
						email: "@email('@qq.com')",
						phone: /^1[0-9]{10}$/,
						regin: "@region",
						url: "@url",
						date: "@date('yyyy-MM-dd')",
					},
				],
			});
			return resultSuccess(mockData.list);
		},
	},
	{
		url: "/mock/tableData",
		method: ["GET"],
		body: ({ query }) => {
			const { page, limit } = query;
			const mockData = Mock.mock({
				"list|30": [
					{
						id: "@id",
						name: "@county(true)" + " xxx广场",
						address: "xxx公寓中庭榕树下",
						"mechanism|1": [1, 2, 3, 4, 5],
						phone: /^1[0-9]{10}$/,
						time: ["@time('HH:mm')", "@time('HH:mm')"],
						"isSupport|1": [0, 1],
						image: "https://img2.baidu.com/it/u=417454395,2713356475&fm=253&fmt=auto?w=200&h=200",
					},
				],
			});
			return pageResultSuccess(Number(page), Number(limit), mockData.list);
		},
	},
	{
		url: "/mock/hospitalData",
		method: ["GET"],
		body: ({ query }) => {
			const { page, limit } = query;
			const mockData = Mock.mock({
				"list|38": [
					{
						id: "@id",
						name: "@province()@city()第@cword('一二三四五六七')人民医院",
						address: "@county(true) @cword(2)@cword('东南西北上下一二三四五')路@integer(1, 99)号",
						principal: "@cname()",
						phone: /^1[1-9][3-9]{9}$/,
						carNum: "@integer(1, 10)",
					},
				],
			});
			return pageResultSuccess(Number(page), Number(limit), mockData.list);
		},
	},
	{
		url: "/mock/ambulanceData",
		method: ["GET"],
		body: ({ query }) => {
			const { page, limit } = query;
			const mockData = Mock.mock({
				"list|38": [
					{
						id: "@id",
						ownHosp: "@province()@city()第@cword('一二三四五六七')人民医院",
						carNo: "@cword('京沪粤桂豫宁川津藏浙')@character('upper')@cword('0123456789ABCDEFGHJKL', 5)",
						factoryNo: "@string('upper', 3)@string('number', 5)",
						price: "@float(20, 59, 1, 2)",
						buyDate: "@date('yyyy-MM-dd')",
						useMiles: "@float(0, 99, 1, 2)",
					},
				],
			});
			return pageResultSuccess(Number(page), Number(limit), mockData.list);
		},
	},
	{
		url: "/mock/userData",
		method: ["GET"],
		body: ({ query }) => {
			const { page, limit } = query;
			const fixedData = [
				{
					id: "admin",
					account: "admin",
					nickName: "admin",
					roles: ["admin"],
					phone: "15912345678",
					email: "pc.vue.template@admin.com",
					status: 1,
					description: "超级管理员，不可删除",
					createTime: "2021-12-12 12:12:12",
				},
				{
					id: "common",
					account: "common",
					nickName: "common",
					roles: ["common"],
					phone: "15912345678",
					email: "pc.vue.template@admin.com",
					status: 1,
					description: "用于角色演示，不可删除",
					createTime: "2021-12-12 12:12:12",
				},
				{
					id: "test",
					account: "test",
					nickName: "test",
					roles: ["test"],
					phone: "15912345678",
					email: "pc.vue.template@admin.com",
					status: 1,
					description: "用于角色演示，不可删除",
					createTime: "2021-12-12 12:12:12",
				},
				{
					id: "commonTest",
					account: "commonTest",
					nickName: "commonTest",
					roles: ["common", "test"],
					phone: "15912345678",
					email: "pc.vue.template@admin.com",
					status: 1,
					description: "用于角色演示，不可删除",
					createTime: "2021-12-12 12:12:12",
				},
			];
			const mockData = Mock.mock({
				"list|30": [
					{
						id: "@id",
						account: "@last",
						nickName: "@cname",
						"roles|1": [["common"], ["test"], ["common", "test"]],
						phone: /^1[0-9]{10}$/,
						email: "@email",
						status: "@integer(0, 1)",
						description: "测试用户",
						createTime: "@date('yyyy-MM-dd HH:mm:ss')",
					},
				],
			});
			return pageResultSuccess(Number(page), Number(limit), [...fixedData, ...mockData.list]);
		},
	},
	{
		url: "/mock/roleData",
		method: ["GET"],
		body: ({ query }) => {
			const { page, limit, isAll } = query;
			const fixedData = [
				{
					id: Mock.Random.id(),
					label: "超级管理员",
					value: "admin",
					index: 1,
					status: 1,
					createTime: "2021-12-12 12:12:12",
					description: "超级管理员，不可删除",
					permissions: [
						"home",
						"system",
						"user",
						"role",
						"iconList",
						"elementPlusIcons",
						"fontAwesomeIcons",
						"iconfontIcons",
						"demo",
						"editorDemo",
						"noticeBarDemo",
						"iconSelectorDemo",
						"iconDemo",
						"tableDemo",
						"filterDemo",
						"filterDetails",
						"filterDetails1",
						"map",
					],
				},
				{
					id: Mock.Random.id(),
					label: "普通",
					value: "common",
					index: 2,
					status: 1,
					createTime: "2021-12-12 12:12:12",
					description: "测试专用，不可删除",
					permissions: [
						"home",
						"iconList",
						"elementPlusIcons",
						"fontAwesomeIcons",
						"iconfontIcons",
						"demo",
						"editorDemo",
						"noticeBarDemo",
						"iconSelectorDemo",
						"iconDemo",
						"tableDemo",
						"filterDemo",
						"filterDetails",
						"filterDetails1",
						"map",
					],
				},
				{
					id: Mock.Random.id(),
					label: "测试",
					value: "test",
					index: 3,
					status: 1,
					createTime: "2021-12-12 12:12:12",
					description: "测试专用，不可删除",
					permissions: ["home", "system", "user", "role"],
				},
			];
			if (isAll) return resultSuccess(fixedData);
			return pageResultSuccess(Number(page), Number(limit), fixedData);
		},
	},
]);
